#pragma once


#include "RayTracer/RayTracer.hpp"
#include "Math/Ray3.hpp"
#include <vector>

// Forward references.
class JSONValue;


namespace RayTracer
{
	// Forward references.
	class Scene;
	class Material;

	//////////////////////////////////////////////////////////////////////////
	class BEGIN_ALIGNED( Model, 16 )
	{
	public:
		ALIGNED_MEMORY( Model, 16 );

		Model();
		virtual ~Model();

		virtual bool					Parse( Scene& s, JSONValue* v );
		virtual bool					Intersect( Vector3::ParamType_t origin, Vector3::ParamType_t dir, float& t ) const=0;
		virtual Vector3					Normal( const Vector3& hp ) const;
		RayTracer::Material*			Material() const						{return mpMaterial;}

		static Model*					ParseModel( Scene& s, JSONValue* v );

	protected:
		RayTracer::Material*			mpMaterial;
	} END_ALIGNED( Model, 16 );


	//////////////////////////////////////////////////////////////////////////
	class ModelSet
	{
	public:
		ModelSet();
		~ModelSet();

		bool							Parse( Scene& s, JSONValue* v );

		Material*						Intersect( const Math::Ray3& r, Vector3& hp, Vector3& n, float& t ) const;
		bool							Shadowed( const Math::Ray3& r, float dist ) const;

	private:
		typedef std::vector< Model* >		ModelVector_t;

		ModelVector_t			mModels;
	};
}
